#coding:utf-8

class PaperRequireDomain

  def self.all
    PaperRequireRepo.all.map do |e|
      [e.manager_id, e.position_id]
    end.uniq.map do |mid, pid|
      PaperRequireRepo.group(mid, pid)
    end
  end

    
  

  def self.create params
    manager_id     = params[:manager_id]
    position_id    = params[:position_id]

    params[:paper_type_ids].each do |id|
      args = {manager_id: manager_id, position_id: position_id, paper_type_id: id}
      if PaperRequireRepo.where(args).empty?
        PaperRequireRepo.create(args)
      end
    end

    PaperRequireRepo.group(manager_id, position_id)
  end
end
